package com.zhd.grpcservice.service;

import com.zhd.grepcommon.user.BooleanReply;
import com.zhd.grepcommon.user.User;
import com.zhd.grepcommon.user.UserServiceGrpc;
import io.grpc.stub.StreamObserver;
import net.devh.springboot.autoconfigure.grpc.server.GrpcService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @Author: zhanghuadi
 * @CreateDate: 2019/3/9 0009 14:55
 * @UpdateDate: 2019/3/9 0009 14:55
 * @UpdateRemark:
 * @Version: 1.0
 * @Description:
 */
@GrpcService(UserGrpcService.class)
public class UserGrpcService extends UserServiceGrpc.UserServiceImplBase {

    private static final Logger LOGGER = LoggerFactory.getLogger(UserGrpcService.class);

    @Override
    public void addUser(User request, StreamObserver<BooleanReply> responseObserver) {

        LOGGER.info("User={id={}, username={}, address={}, age={}, sex={}, createtime={}, updatetime={}}",
                request.getId(),request.getUsername(),request.getAddress(),request.getAge(),request.getSex(),request.getCreatetime(),request.getUpdatetime());

        BooleanReply reply = BooleanReply.newBuilder().setReply(true).build();
        responseObserver.onNext(reply);
        responseObserver.onCompleted();
    }

}
